Programming exercise chapter 2